#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    int n;
    for(int i=0;i<t;i++){
        cin>>n;
        int num[n]={0};
        int nc[n]={0};
        bool col[n];
        for(int j=0;j<n;j++){
            cin>>num[j];
            col[j]=false;
        }
        int max_nc=0;
        for(int j=0;j<(1<<n);j++){
            for(int b=0;b<n;b++){
                int p=j&(1<<(n-b));
                if(p>0){
                    col[b]=true;
                }else{
                    col[b]=false;
                }
                bool same=false;
                for(int k=b-1;k>=0;k--){
                    if(col[b]==col[k]){
                        same=true;
                        if(num[k]==num[b]){
                            nc[b]=num[b];
                        }else{
                            nc[b]=0;
                        }
                    }
                }
                if(!same){
                    nc[b]=0;
                }
            }
            int nc_s=0;
            for(int b=0;b<n;b++){
                nc_s+=nc[b];
            }
            if(nc_s>max_nc){
                max_nc=nc_s;
            }
        }
        cout<<max_nc<<"\n";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
